<!DOCTYPE html>
<html>
<head>
    <title>入院办理--中软高科-2015</title>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" href="../Css/bootstrap.css"/>
    <link rel="stylesheet" type="text/css" href="../Css/bootstrap-responsive.css"/>
    <link rel="stylesheet" type="text/css" href="../Css/style.css"/>
    <script type="text/javascript" src="../Js/jquery.js"></script>
    <script type="text/javascript" src="../Js/jquery.sorted.js"></script>
    <script type="text/javascript" src="../Js/bootstrap.js"></script>
    <script type="text/javascript" src="../Js/ckform.js"></script>
    <script type="text/javascript" src="../Js/common.js"></script>
    <script type="text/javascript" src="../Js/pagination.js"></script>
    <link rel="stylesheet" type="text/css" href="../Css/pagination.css" />

    <style type="text/css">
        body {
            padding-bottom: 40px;
        }

        .sidebar-nav {
            padding: 9px 0;
        }

        @media (max-width: 980px) {
            /* Enable use of floated navbar text */
            .navbar-text.pull-right {
                float: none;
                padding-left: 5px;
                padding-right: 5px;
            }
        }


    </style>
    <script type="text/javascript">
        $(function () {
            $('#newNav').click(function () {
                window.location.href = "add.html";
            });
            initData("", "", "", "", "", "")
        });

        function initData(behId, doctorName, startTime, endTime, keShi) {
            $.ajax({
                url: "selectBeHospital",
                data: {
                    'behId': behId,
                    "doctorName": doctorName,
                    'startTime': startTime,
                    'endTime': endTime,
                    'keShi': keShi
                },
                type: 'post',
                dataType: 'json',
                success: function (data) {
                    //清空下级标签
                    $("#xunhuan").empty();
                    let page = data.data.pageInfo;
                    //let param = data.data.param;
                    let list = page.list;
                    console.log(list)
                    //遍历数据
                    $.each(list, function (index, item) {
                        //缴费
                        let jiaofei = "";
                        if (item.priceStatus==1&&item.behCloseprice!=1) {
                            jiaofei = "\t\t\t\t<a href=\"add_many.html?id=" + item.behId + "\">缴纳押金</a>&nbsp;&nbsp;&nbsp;\n";
                        }

                        //住院
                        let zhuyuan = "";
                        //出院
                        let tuiyuan = "";
                        if (item.behCloseprice==1){
                            if (item.hosrState==0 || item.hosrState==1){
                                zhuyuan = "\t\t\t\t<a onclick='updateOne(" + item.behId + ",2)' href=\"#\">出院</a>&nbsp;&nbsp;&nbsp;\n";
                                tuiyuan = "\t\t\t\t<a onclick='updateOne(" + item.behId + ",4)' href=\"#\">退院</a>&nbsp;&nbsp;&nbsp;\n";
                            }
                        }
                        let myxunhuan = "" +
                            "\t     <tr >\n" +
                            "         \t<td style=\"vertical-align:middle;\"><input type=\"checkbox\" name=\"check\" value=\"" + item.behId + "\"></td>\n" +
                            "            <td style=\"vertical-align:middle;\">" + item.behId + "</td>\n" +
                            "            <td style=\"vertical-align:middle;\">" + item.hosrName + "</td>\n" +
                            "            <td style=\"vertical-align:middle;\">" + item.behPatbed + "</td>\n" +
                            "            <td style=\"vertical-align:middle;\">" + item.hosrPhone + "</td>\n" +
                            "            <td style=\"vertical-align:middle;\">" + item.behAntecedent + "</td>\n" +
                            "            <td style=\"vertical-align:middle;\">" + item.doctorName + "</td>\n" +
                            "            <td style=\"vertical-align:middle;\">" + item.behIntime + "</td>\n" +
                            "            <td style=\"vertical-align:middle;\">" + item.keShi + "</td>\n" +
                            "            <td style=\"vertical-align:middle;\">" + formartStatus(item.hosrState) + "</td>\n" +
                            "            <td style=\"vertical-align:middle;\">\n" +
                            "\t\t\t\t<a href=\"look.html?id=" + item.behId + "\">详情>></a>&nbsp;&nbsp;&nbsp;\n" +
                            "\t\t\t\t<a href=\"edit.html?id=" + item.behId + "\">更改</a>&nbsp;&nbsp;&nbsp;\n" +
                            jiaofei+
                            zhuyuan+
                            tuiyuan+
                            "\t\t\t</td>\n" +
                            "        </tr>";

                        $("#xunhuan").append(myxunhuan)
                    });

                    //分页
                    // $("#pageNum").text(page.pageNum + "/" + page.pages);
                    // $("#totalMsg").text(page.pages);

                    new Pagination({
                        element: '#pages',
                        type: 2,
                        layout: 'prev, pager, next, total, jumper',
                        pageIndex: 1,
                        pageSize: 5,
                        pageCount: 9,
                        total: page.total,
                        singlePageHide: false,
                        disabled: true,
                        currentChange: function (index) {
                            console.log(index);

                            let behId = $("input[name='behId']").val();
                            let doctorName = $("input[name='doctorName']").val();
                            let keShi = $("input[name='keShi']").val();
                            let startTime = $("input[name='startTime']").val();
                            let endTime = $("input[name='endTime']").val();
                            $.ajax({
                                url: "selectBeHospital",
                                data: {
                                    'behId': behId,
                                    "doctorName": doctorName,
                                    'startTime': startTime,
                                    'endTime': endTime,
                                    'keShi': keShi,
                                    'pageNum':index
                                },
                                type: 'post',
                                dataType: 'json',
                                success: function (data) {
                                    //清空下级标签
                                    $("#xunhuan").empty();
                                    let page = data.data.pageInfo;
                                    //let param = data.data.param;
                                    let list = page.list;
                                    console.log(list)
                                    //遍历数据
                                    $.each(list, function (index, item) {
                                        //缴费
                                        let jiaofei = "";
                                        if (item.priceStatus == 1 && item.behCloseprice != 1) {
                                            jiaofei = "\t\t\t\t<a href=\"add_many.html?id=" + item.behId + "\">缴纳押金</a>&nbsp;&nbsp;&nbsp;\n";
                                        }

                                        //住院
                                        let zhuyuan = "";
                                        //出院
                                        let tuiyuan = "";
                                        if (item.behCloseprice == 1) {
                                            if (item.hosrState == 0 || item.hosrState == 1) {
                                                zhuyuan = "\t\t\t\t<a onclick='updateOne(" + item.behId + ",2)' href=\"#\">出院</a>&nbsp;&nbsp;&nbsp;\n";
                                                tuiyuan = "\t\t\t\t<a onclick='updateOne(" + item.behId + ",4)' href=\"#\">退院</a>&nbsp;&nbsp;&nbsp;\n";
                                            }
                                        }
                                        let myxunhuan = "" +
                                            "\t     <tr >\n" +
                                            "         \t<td style=\"vertical-align:middle;\"><input type=\"checkbox\" name=\"check\" value=\"" + item.behId + "\"></td>\n" +
                                            "            <td style=\"vertical-align:middle;\">" + item.behId + "</td>\n" +
                                            "            <td style=\"vertical-align:middle;\">" + item.hosrName + "</td>\n" +
                                            "            <td style=\"vertical-align:middle;\">" + item.behPatbed + "</td>\n" +
                                            "            <td style=\"vertical-align:middle;\">" + item.hosrPhone + "</td>\n" +
                                            "            <td style=\"vertical-align:middle;\">" + item.behAntecedent + "</td>\n" +
                                            "            <td style=\"vertical-align:middle;\">" + item.doctorName + "</td>\n" +
                                            "            <td style=\"vertical-align:middle;\">" + item.behIntime + "</td>\n" +
                                            "            <td style=\"vertical-align:middle;\">" + item.keShi + "</td>\n" +
                                            "            <td style=\"vertical-align:middle;\">" + formartStatus(item.hosrState) + "</td>\n" +
                                            "            <td style=\"vertical-align:middle;\">\n" +
                                            "\t\t\t\t<a href=\"look.html?id=" + item.behId + "\">详情>></a>&nbsp;&nbsp;&nbsp;\n" +
                                            "\t\t\t\t<a href=\"edit.html?id=" + item.behId + "\">更改</a>&nbsp;&nbsp;&nbsp;\n" +
                                            jiaofei +
                                            zhuyuan +
                                            tuiyuan +
                                            "\t\t\t</td>\n" +
                                            "        </tr>";

                                        $("#xunhuan").append(myxunhuan)
                                    });
                                }
                            });
                        }
                    });
                }
            });
        }

        function updateOne(id,status){
            $.ajax({
                url: "updateBehStateStatus",
                data: {"hosrId": id, 'hosrState': status},
                traditional: true,
                success: function (resp) {
                    if (resp.response.flag) {
                        initData("", "", "", "", "")
                    } else {
                        alert(resp.response.errorMsg);
                    }
                }
            })

            initData("", "", "", "", "");

            return false;
        }

        //查询
        function queryHospital() {
            let behId = $("input[name='behId']").val();
            let doctorName = $("input[name='doctorName']").val();
            let keShi = $("input[name='keShi']").val();
            let startTime = $("input[name='startTime']").val();
            let endTime = $("input[name='endTime']").val();

            initData(behId, doctorName, startTime,endTime, keShi);
        }

        //重置
        function resetPage() {
            $("input[name='behId']").val("");
            $("input[name='doctorName']").val("");
            $("input[name='keShi']").val("");
            $("input[name='startTime']").val("");
            $("input[name='endTime']").val("");

            initData("", "", "", "", "")
        }

        function formartStatus(num) {
            //挂号状态：0挂号 1已住院 2已出院 3已退号
            if (num == 0) {
                return "挂号";
            }
            if (num == 1) {
                return "已住院";
            }
            if (num == 2) {
                return "已出院";
            }
            if (num == 3) {
                return "已退号";
            }
            if (num == 4) {
                return "已退院";
            }
        }

        function checkall() {
            var alls = document.getElementsByName("check");
            var ch = document.getElementById("checkall");
            if (ch.checked) {
                for (var i = 0; i < alls.length; i++) {
                    alls[i].checked = true;
                }
            } else {
                for (var i = 0; i < alls.length; i++) {
                    alls[i].checked = false;
                }
            }
        }

        function delAll() {
            var alls = document.getElementsByName("check");
            var ids = new Array();
            for (var i = 0; i < alls.length; i++) {
                if (alls[i].checked) {
                    ids.push(alls[i].value);
                }
            }
            if (ids.length > 0) {
                if (confirm("确认操作?")) {
                    alert("成功!");
                }
            } else {
                alert("请选中要操作的项");
            }
        }

        //导出excel
        function exportExcel() {
            var ids = [];
            $("input[name='check']:checked").each(function (i) {
                ids.push($(this).val())
                //$("body").append("<p>"+$(this).val()+"</p>")
            })
            //console.log(ids)
            if (ids.length > 0) {
                $.ajax({
                    url: "exportExcel",
                    data: {"id": ids},
                    traditional: true,
                    success: function (resp) {
                        if (resp.response.flag) {
                            window.location.href = "http://localhost:8080/downloadFile?fileName=hospitalMsg.xls"
                        } else {

                        }
                    }
                })
            } else {
                alert("请选择要导出的数据");
            }
        }

        //批量修改挂号状态
        function updateHospitalStatus(status) {
            var ids = [];
            $("input[name='check']:checked").each(function (i) {
                ids.push($(this).val())
                // $("body").append("<p>"+$(this).val()+"</p>")
            })
            //console.log(ids)
            if (ids.length > 0) {
                $.ajax({
                    url: "updateBehStateStatus",
                    data: {"hosrId": ids, 'hosrState': status},
                    traditional: true,
                    success: function (resp) {
                        if (resp.response.flag) {

                        } else {
                            alert(resp.response.errorMsg);
                        }
                        initData("", "", "", "", "")
                    }
                })
            } else {
                //挂号状态：0挂号 1已住院 2已出院 3已退号
                if (status == 2) {
                    alert("请选择的要出院的患者");
                } else {
                    alert("请选择的要退院的患者");
                }
            }
        }
    </script>
</head>
<body>

<form action="../../index.html" method="post" class="definewidth m20">
    <table class="table table-bordered table-hover definewidth m10">
        <tr>
            <td width="10%" class="tableleft">病例号：</td>
            <td><input type="text" name="behId" value=""/></td>

            <td width="10%" class="tableleft">主治医生：</td>
            <td><input type="text" name="doctorName" value=""/></td>

            <td width="10%" class="tableleft">科室：</td>
            <td><input type="text" name="keShi" value=""/></td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">住院时间：</td>
            <td colspan="5">
                <input type="date" name="startTime" value=""/>&nbsp;至&nbsp;<input type="date" name="endTime" value=""/>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <input type="button" class="btn btn-primary" onclick="queryHospital()" value="查询"/>
                <input class="btn btn-primary" type="button" onclick="resetPage()" value="清空"/>
            </td>
        </tr>
    </table>
</form>

<table class="table table-bordered table-hover definewidth m10">
    <thead>
    <tr>
        <th><input type="checkbox" id="checkall" onChange="checkall();"></th>
        <th>病历号</th>
        <th>姓名</th>
        <th>床位号</th>
        <th>联系电话</th>
        <th>押金</th>
        <th>主治医生</th>
        <th>入院时间</th>
        <th>科室</th>
        <th>状态</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody id="xunhuan">
    <tr>
        <td style="vertical-align:middle;"><input type="checkbox" name="check" value="1"></td>
        <td style="vertical-align:middle;">1103</td>
        <td style="vertical-align:middle;">黄飞鸿</td>
        <td style="vertical-align:middle;">4343</td>
        <td style="vertical-align:middle;">13127653423</td>
        <td style="vertical-align:middle;">2000元</td>
        <td style="vertical-align:middle;">程俊</td>
        <td style="vertical-align:middle;">2015-01-05 12:33:56</td>
        <td style="vertical-align:middle;">血液科</td>
        <td style="vertical-align:middle;">已住院</td>
        <td style="vertical-align:middle;">
            <a href="look.html">详情>></a>&nbsp;&nbsp;&nbsp;
            <a href="edit.html">更改</a>&nbsp;&nbsp;&nbsp;
            <a href="add_many.html">缴纳押金</a>&nbsp;&nbsp;&nbsp;
        </td>
    </tr>
    </tbody>
</table>

<table class="table table-bordered table-hover definewidth m10">
    <tr>
        <th colspan="5">
            <div class="inline pull-right page" id="pages">
<!--                <a href='#'>第一页</a> <a href='#'>上一页</a> <span class='current'>1</span><a href='#'>2</a><a-->
<!--                    href='/chinapost/index.php?m=Label&a=index&p=3'>3</a><a href='#'>4</a><a href='#'>5</a> <a href='#'>下一页</a>-->
<!--                <a href='#'>最后一页</a>-->
<!--                &nbsp;&nbsp;&nbsp;共<span class='current' id="totalMsg">32</span>条记录<span class='current' id="pageNum"> 1/33 </span>页-->
            </div>
            <div>
                <button type="button" class="btn btn-success" id="newNav">添加住院信息</button>&nbsp;&nbsp;&nbsp;
                <button type="button" class="btn btn-success" id="chu" onclick="updateHospitalStatus(2)">出院</button>&nbsp;&nbsp;&nbsp;
                <button type="button" class="btn btn-success" id="tui" onclick="updateHospitalStatus(4)">退院</button>&nbsp;&nbsp;&nbsp;
                <button type="button" class="btn btn-success" id="exportExcel" onclick="exportExcel()">导出Excel</button>
            </div>

        </th>
    </tr>
</table>

</body>
</html>
